Skip to content

assistant transfer: cap pair lock and voice receipt reads while streaming - #746

Merged
joshuaswarren merged 1 commit into
joshuaswarren:mainfrom
only21mil:fix/transfer-json-member-cap
Nov 23, 2026
Merged

joshuaswarren merged 1 commit into
joshuaswarren:mainfrom
only21mil:fix/transfer-json-member-cap

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

When a bundle's pair lock or voice receipt declares a large size, import reads the whole member into memory before checking its size or hash.

This follows up the review note on #740. _json_member joins every chunk of a member, then parses it. The only bound is the member's declared size in the zip's central directory, and nothing checks that size before this read. Deflate compresses a run of whitespace about a thousandfold, so a 520 KB bundle can carry a 512 MiB lock. stage_import buffers all of it while deriving the bundle's licenses, before the size and hash checks.

Fix

  • _member_chunks takes an optional byte limit and raises UnsafeArchive as soon as the decompressed stream passes it, reading at most one byte past the limit. The count comes from bytes actually read, so neither header size field can raise the limit.
  • _json_member now requires max_bytes: 1 MiB for pair locks and voice receipts (real ones are a few KB), and 64 MiB for the manifest, the same limit its declared-size check already uses.
  • Payload extraction keeps the unlimited stream: each member's declared size must equal the manifest's before it starts, and the size and hash are checked after.

Verification

A new test, test_oversized_lock_or_receipt_stops_at_the_byte_cap, first checks that a normal bundle with a voice pack inspects and imports. Then, for both the lock and the receipt, it builds a member padded to 32 MiB and deflated to under 1 MiB, with the local header claiming 16 bytes. It expects UnsafeArchive with traced memory rising less than 8 MiB.

base 2aef87273 head
new test, Python 3.14 and 3.11 2 subtests fail (bundle accepted) pass
512 MiB lock in a 520 KB bundle, peak RSS added during the license check +1025 MiB, 1.6 s, accepted +2 MiB, 3 ms, UnsafeArchive

All the Linux steps of collectors.yml pass on Python 3.14 and on 3.11, run one after the other. privacy_check.py reports clean.

Repro output
== base (2aef87273) py3.14
bundle 530922 bytes; everyday/lock.json: compressed 522256, central-directory size 536871775, local header size 16
provenance: mlx-omarchy None mx=None verified=no-mlx harness=2aef87273 files=unresolved
outcome: accepted (whole lock read into memory)
lock read: 1.580 s; peak RSS 1048 MiB (+1025 MiB over pre-read)
== base (2aef87273) py3.11
bundle 530921 bytes; everyday/lock.json: compressed 522255, central-directory size 536871775, local header size 16
provenance: mlx-omarchy None mx=None verified=no-mlx harness=2aef87273 files=unresolved
outcome: accepted (whole lock read into memory)
lock read: 1.547 s; peak RSS 1049 MiB (+1026 MiB over pre-read)
== head (b707d094a) py3.14
bundle 530923 bytes; everyday/lock.json: compressed 522257, central-directory size 536871775, local header size 16
provenance: mlx-omarchy None mx=None verified=no-mlx harness=b707d094a files=unresolved
outcome: UnsafeArchive: bundle member everyday/lock.json exceeds 1048576 bytes
lock read: 0.003 s; peak RSS 24 MiB (+2 MiB over pre-read)
== head (b707d094a) py3.11
bundle 530920 bytes; everyday/lock.json: compressed 522254, central-directory size 536871775, local header size 16
provenance: mlx-omarchy None mx=None verified=no-mlx harness=b707d094a files=unresolved
outcome: UnsafeArchive: bundle member everyday/lock.json exceeds 1048576 bytes
lock read: 0.003 s; peak RSS 25 MiB (+2 MiB over pre-read)

Generated with Claude Opus 5.5 in T3 Code Nightly

…ming

_json_member buffered a whole member before parsing it, bounded only by
the member's declared size. A pair lock or voice receipt declared at
hundreds of MiB, deflated to a few hundred KB, was read fully into memory
before its size or hash was checked.

_member_chunks now takes a byte limit and raises UnsafeArchive as soon
as the decompressed stream passes it, reading at most one byte past the
limit. _json_member requires a cap: 1 MiB for pair locks and voice
receipts, 64 MiB for the manifest (the same limit its declared-size
check already uses).

Follows up joshuaswarren#740.
@joshuaswarren

Copy link
Copy Markdown
Owner

GREEN at 54c371c
Model: cognition/swe-2

@kilo-code-bot

kilo-code-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • serve/mlx_omarchy_assistant/transfer.py - 0 issues
  • tests/test_assistant_transfer.py - 0 issues

Reviewed by free · Input: 130.2K · Output: 286.8K · Cached: 7.6M

@joshuaswarren

Copy link
Copy Markdown
Owner

GREEN at 54c371c
Model: zai/glm-5.3-flash

@joshuaswarren
joshuaswarren merged commit a3509ce into joshuaswarren:main Nov 23, 2026
5 checks passed
@joshuaswarren

Copy link
Copy Markdown
Owner

Thanks @only21mil — lock and receipt archive members now have real byte caps, so a hostile or corrupt bundle can no longer inflate unbounded memory in _member_chunks/_json_member. Merged at a3509ce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants